<?php

use \App\Models\EmailVerification;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateEmailVerificationsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('email_verifications', function (Blueprint $table) {

            $table->increments('id');

            $table->string('email')->index();
            $table->string('token');

            $table->enum('type', [
                EmailVerification::TYPE_EMAIL,
                EmailVerification::TYPE_RESET_PASSWORD,
            ]);

            $table->timestamp('expired_at');

            $table->unique(['email', 'type']);

            $table->comment = '邮箱验证表';
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('email_verifications');
    }
}
